<template>
  <div class="config-layout">
    <el-container>
      <el-aside width="250px" class="sidebar">
        <div class="sidebar-header">
          <h3>AI Agent 配置系统</h3>
        </div>
        <el-menu :default-active="activeMenu" class="config-menu" router @select="handleMenuSelect">
          <el-menu-item index="/config/scene">
            <el-icon>
              <Grid />
            </el-icon>
            <span>场景管理</span>
          </el-menu-item>
          <el-menu-item index="/config/agent">
            <el-icon>
              <Avatar />
            </el-icon>
            <span>智能体管理</span>
          </el-menu-item>
          <el-menu-item index="/config/dialog">
            <el-icon>
              <ChatDotRound />
            </el-icon>
            <span>AI助手管理</span>
          </el-menu-item>
          <el-menu-item index="/config/memory">
            <el-icon>
              <Cpu />
            </el-icon>
            <span>记忆管理</span>
          </el-menu-item>
          <el-menu-item index="/config/tools">
            <el-icon>
              <Tools />
            </el-icon>
            <span>基础工具管理</span>
          </el-menu-item>
          <el-menu-item index="/config/mcp">
            <el-icon>
              <Connection />
            </el-icon>
            <span>MCP接入管理</span>
          </el-menu-item>
          <el-menu-item index="/config/rag">
            <el-icon>
              <Document />
            </el-icon>
            <span>Modular RAG管理</span>
          </el-menu-item>
          <el-menu-item index="/config/permission">
            <el-icon>
              <Lock />
            </el-icon>
            <span>接入权限管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header class="config-header">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统配置</el-breadcrumb-item>
            <el-breadcrumb-item v-if="currentPageTitle">{{ currentPageTitle }}</el-breadcrumb-item>
          </el-breadcrumb>
          <div class="header-actions">
            <el-button @click="goBack">
              <el-icon>
                <ArrowLeft />
              </el-icon>
              返回首页
            </el-button>
          </div>
        </el-header>

        <el-main class="config-content">
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

const activeMenu = ref('/config/scene')

const menuTitles: Record<string, string> = {
  '/config/scene': '场景管理',
  '/config/dialog': 'AI助手管理',
  '/config/memory': '记忆管理',
  '/config/tools': '基础工具管理',
  '/config/rag': 'Modular RAG管理',
  '/config/agent': '智能体管理',
  '/config/mcp': 'MCP接入管理',
  '/config/permission': '接入权限管理'
}

const currentPageTitle = computed(() => {
  return menuTitles[route.path] || ''
})

const handleMenuSelect = (index: string) => {
  activeMenu.value = index
}

const goBack = () => {
  router.push('/config/scene')
}

watch(() => route.path, (newPath) => {
  if (newPath.startsWith('/config/')) {
    activeMenu.value = newPath
  }
}, { immediate: true })
</script>

<style scoped>
.config-layout {
  height: 100vh;
}

.sidebar {
  background: #fff;
  border-right: 1px solid #e4e7ed;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #e4e7ed;
  text-align: center;
}

.sidebar-header h3 {
  margin: 0;
  color: #303133;
}

.config-menu {
  border-right: none;
}

.config-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border-bottom: 1px solid #e4e7ed;
  padding: 0 20px;
}

.config-content {
  background: #f5f7fa;
  padding: 20px;
}
</style>